import { type IApi, defaultWithIApi } from './api'
import type { BodyType } from './basic'

export const defaultWithIStressCase: IStressCase = {
    ...defaultWithIApi,
    projectId: -1,
    jmxUrl: '',
    relation: '',
    // assertion: '',
    stressSourceType: 'JMX',
    threadGroupConfig: '',
    stressCaseDetailSaveReqList: [],
    beanShell: [],
    jsr223Sampler:[]
}

export interface IStressCase extends Omit<IApi, 'rest'> {
    jmxUrl: string
    relation: string
    projectId: number
    stressSourceType: string
    // assertion: string
    threadGroupConfig: string,
    beanShell: Array<IStressCaseBeanShell>,
    jsr223Sampler: Array<IStressCaseJSR223>,
    stressCaseDetailSaveReqList: Array<IStressCaseDetailSaveReq>
}

export const defaultWithIStressCaseRelation: IStressCaseRelation = {
    sourceType: 'csv',
    recycle: true,
    delimiter: ',',
    ignoreFirstLine: true,
    variableNames: 'id, name',
    remoteFilePath: '',
    name: 'CSV 数据集合',
}

export interface IStressCaseRelation {
    sourceType: string
    recycle: boolean
    delimiter: string
    ignoreFirstLine: boolean
    variableNames: string
    remoteFilePath: string
    name: string
}

export const defaultWithIStressCaseAssertion: IStressCaseAssertion = {
    name: '',
    action: 'EQUAL',
    from: 'RESPONSE_CODE',
    value: '200',
}

export interface IStressCaseAssertion {
    name: string
    action: string
    from: string
    value: string
}

export const defaultWithIStressCaseThreadGroupConfig: IStressCaseThreadGroupConfig =
{
    threadGroupName: '',
    numThreads: 1,
    rampUp: 0,
    loopCount: 1,
    schedulerEnabled: false,
    duration: 0,
    delay: 0,
}

export interface IStressCaseThreadGroupConfig {
    threadGroupName: string
    numThreads: number
    rampUp: number
    loopCount: number
    schedulerEnabled: boolean
    duration: number
    delay: number
}

export const defaultWithIStressCaseDetailSaveReq: IStressCaseDetailSaveReq = {
    protocol: '',
    domain: '',
    port: '',
    contentEncoding: '',
    name: '',
    description: '无描述',
    path: '/',
    method: 'GET',
    query: '[]',
    relation: '[]',
    assertion: '[]',
    header: '[]',
    body: '[]',
    bodyType: 'JSON',
    interfaceType: 'ORDINARY',
    relationParam: '[]',
    formModelExpand: {
        relation: false,
        assertion: false,
        relationData: [],
        assertionData: [],
    },
    index: -1,
    beanShellPre: [],
    beanShellPost: [],
    jsr223Pre: [],
    jsr223Post: []
}

export interface IStressCaseDetailSaveReq {
    protocol: string,
    domain: string,
    port: string,
    contentEncoding: string,
    name: string,
    description: string,
    path: string,
    method: string,
    query: string,
    relation: string,
    assertion: string,
    header: string,
    body: string,
    bodyType: BodyType,
    interfaceType: string,
    relationParam?: string,
    formModelExpand?: IFormModelExpand,
    index?: number,
    beanShellPre: Array<IStressCaseBeanShellInner>,
    beanShellPost: Array<IStressCaseBeanShellInner>,
    jsr223Pre: Array<IStressCaseJSR223>,
    jsr223Post: Array<IStressCaseJSR223>,

}

export interface IFormModelExpand {
    relation: boolean
    assertion: boolean
    relationData: IStressCaseRelation[]
    assertionData: IStressCaseAssertion[]
}

export interface IStressCaseBeanShell{
    name: string,
    description: string,
    beanShellQuery: string,
    beanShellFileName: string,
    beanShellParam: string,
    sort: number,
}

export const defaultWithIStressCaseBeanShell: IStressCaseBeanShell = {
    name: '',
    description: '',
    beanShellQuery: '',
    beanShellFileName: '',
    beanShellParam: '',
    sort: 0
}

export interface IStressCaseJSR223{
    name: string,
    description: string,
    script: string,
    parameters: string,
    filename: string,
    cacheKey: string | boolean,
    scriptLanguage: string,
    sort: number,
}

export const defaultWithIStressCaseJSR223: IStressCaseJSR223 = {
    name: '',
    description: '',
    script: '',
    parameters: '',
    filename: '',
    cacheKey: true,
    scriptLanguage: 'java',
    sort: 0
}

export interface IStressCaseBeanShellInner{
    name: string,
    description: string,
    script: string,
    parameter: string,
    fileName: string,
    sort: number,
}

export const defaultWithIStressCaseBeanShellInner: IStressCaseBeanShellInner = {
    name: '',
    description: '',
    script: '',
    parameter: '',
    fileName: '',
    sort: 0
}